<?php
// +----------------------------------------------------------------------
// | 用户管理模型
// +----------------------------------------------------------------------
namespace app\webapp\model;
use think\Model;
use util\Util;

class User extends Model{

    protected $pk       = 'id';
    protected $table    = 'sp_passport_user';

    /**
     * 读取对应用户信息
     * @access public
     */
    public function find_user($param){
        return $this->where($param)->find();
    }


    /**
     * 判断是否有帐号
     * @access public
     */
    public function isFind($param){
        return $this->where($param)->field('id')->find();
    }


    /**
     * 帐号注册
     */
    public function reguser($param){
        $data = [
            'wechat_id'       => $param['wechat_id'],
            'nickname'        => $param['nickname'],
            'create_time'     => time(),
            'update_time'     => time(),
            'last_login_ip'   => Util::getIp(),
            'last_login_time' => time(),
        ];
        $rel = self::insert($data);
        if($rel){
            $data_info = ['uid'=> $rel,'nickname' => $param['nickname']];
            $this->table('sp_passport_info')->insert($data_info);
        }
        return $rel;
    }
}